﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.IO;
using Microsoft.Win32;
using ShapeDemo.UC.WinProp;


namespace ShapeDemo
{
    /// <summary>
    /// Interaction logic for MainForm.xaml
    /// </summary>
    public partial class MainForm : Window
    {
        private string filename = System.Environment.CurrentDirectory + "/ShapeXML/";
        private WinPropPolygon winPolygonProp = new WinPropPolygon();
        private ECanvas Toplayer;
        private TMouse MouseType;
        private PolygonDrawer pgnDrawer;
        private DataIntoXML dtXML;

        public MainForm()
        {
            InitializeComponent();

            MouseType = TMouse.Drawing;

            propertyCanvas.Children.Add(new UC.Empty());
            
            if (!System.IO.Directory.Exists(filename))
            {
                System.IO.Directory.CreateDirectory(filename);
            }

            pgnDrawer = new PolygonDrawer(polygonCanvas, winPolygonProp,winCommonProp);
            

            dtXML = new DataIntoXML(pgnDrawer);

            rbPoint.Checked+=new RoutedEventHandler(rbPoint_Checked);
            rbDraw.Checked+=new RoutedEventHandler(rbDraw_Checked);

            btnPolygon_Click(this, null);

        }

        private void ShowDCanvas()
        {
            polygonCanvas.SetValue(Canvas.ZIndexProperty, 0);

            switch (Toplayer)
            { 
                case ECanvas.Polygon:
                    polygonCanvas.SetValue(Canvas.ZIndexProperty, 6);

                    propertyCanvas.Children.Clear();
                    propertyCanvas.Children.Add(winPolygonProp);

                    break;
            }


        }


        private void btnPolygon_Click(object sender, RoutedEventArgs e)
        {
            Toplayer = ECanvas.Polygon;
            ShowDCanvas();

            winCommonProp.tbIndex.Text = "0";
            winCommonProp.tbContent.Text = "poligono";

            pgnDrawer.Draw();

            pgnDrawer.BindListBox();
        }


        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            dtXML.Save(filename);

            MessageBox.Show("OK!");
        }

        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            pgnDrawer.PgnTooltip = pgnTooltip;
            dtXML.Load(filename);
        }

        private void viewRectTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void rbPoint_Checked(object sender, RoutedEventArgs e)
        {
            pgnDrawer.MouseTye = TMouse.Point;
        }

        private void rbDraw_Checked(object sender, RoutedEventArgs e)
        {
            pgnDrawer.MouseTye = TMouse.Drawing;
        }
        

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            About aboutFrom = new About();
            aboutFrom.ShowDialog();
        }
    }
}